<?php
namespace app\index\controller;

use app\common\model\ZhCheckinLog as ZhCheckinLogModel;

/**
 * 入住记录控制器
 * Class Zhcheckinlog
 * @package app\index\controller
 */
class Zhcheckinlog extends Base
{
    /**
     * [index  列表]
     * @return json
     * @author [C。]
     */
    public function index()
    {
        $param = input('param.');
        $model = new ZhCheckinLogModel;
        $this->getPageAndSize($param);
        $user = $this->user;
        try{
            $data = $model->getAllData(['cid'=>$param['id']],'id','id,content,type,time,create_time');
            foreach($data as &$v){
                if($v['type'] == 1){
                    $v['con'] = '退房:'.date('Y-m-d H:i:s',$v['time']);
                }
                if($v['type'] == 2){
                    $v['con'] = '续住至:'.date('Y-m-d H:i:s',$v['time']);
                }
                if($v['type'] == 3){
                    $v['con'] = '换房至:'.$v['content'];
                }
            }
        }catch (\Exception $e) {
            systembug($e->getMessage(),3,$this->url);
            return admin_json(-1, $e->getMessage());
        }
        return admin_json(1, '获取成功',$data);
    }
    /**
     * [add  添加]
     * @return json
     * @author [C。]
     */
    public function add()
    {
        $param = input('param.');
        $model = new ZhCheckinLogModel;
        try{
            if($param['type'] == 1 || $param['type'] == 2){
                $param['time'] = strtotime($param['time']);
            }
            $model->addData($param);
        }catch (\Exception $e) {
            systembug($e->getMessage(),3,$this->url);
            return admin_json(-1, $e->getMessage());
        }
        return admin_json(1, '操作成功');
    }
}